import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {BlockChaindb} from "../../../../model/BlockChaindb";
import {Binfo} from "../../../../vo/Binfo";
import {BlockchainService} from "../../../../services/blockchain.service";
import {SymessagelistComponent} from "../symessagelist/symessagelist.component";
import {NzModalService} from "ng-zorro-antd/modal";
import {Router} from "@angular/router";

@Component({
  selector: 'app-upblockchaininfo',
  templateUrl: './upblockchaininfo.component.html',
  styleUrls: ['./upblockchaininfo.component.css']
})
export class UpblockchaininfoComponent implements OnInit {
  bl:Array<BlockChaindb>
  b:Binfo
  constructor(private adminService:AdminService,
              private alertService:AlertService,
              private blockchainSrvice:BlockchainService,
              private modal: NzModalService
    , private viewContainerRef: ViewContainerRef,
              private route:Router) {
    this.bl = new Array()
    this.b = new Binfo()

  }

  ngOnInit(): void {
    this.getBlockChainDbs()
    this.getBinfo()
  }

  getBlockChainDbs(){
    this.adminService.getBlockChainDbs().then((data:any)=>{
      if(data.msg == "ok"){
        this.bl = data.list
      }else{
        this.alertService.showError("查询错误")
      }
    })
  }


  getBinfo(){
    this.blockchainSrvice.getChainCodeInfo().then((data:any)=>{

      if(data.msg = "ok"){
        this.b.height = data.height
        this.b.currenthash = data.currenthash
      }else{
        this.b.height = -1
        this.b.currenthash = ""
        this.alertService.showError("获取区块链信息异常，请重试")
      }
    })
  }

  sy(str1:string){
   /* this.modal.create({
      nzTitle: '溯源信息',
      nzContent: SymessagelistComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzWidth:'90%',
      nzComponentParams: {
        str:str1
      }
    })*/



    this.route.navigate(['/blockchain/symessagelist',{"str":str1}])


  }

}
